package com.eblacorp.archive.service.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

import com.eblacorp.archive.annotations.FnTransactional;
import com.eblacorp.archive.util.ce.CeConnectionUtil;

@Aspect
public class CeAuthenticationAspect {

	private CeConnectionUtil ceConnectionUtil;
	
	@Pointcut(value="execution(public * *(..))")
	public void anyPublicMethod() { }
	
	@Around("anyPublicMethod() && @annotation(fnTransactional)")
	public Object handleCeSubject(ProceedingJoinPoint pjp,FnTransactional fnTransactional ) throws Throwable{
		ceConnectionUtil.pushUserSubject();
		Object retValue = null;
		try{
			retValue = pjp.proceed();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			ceConnectionUtil.popUserSubject();
		}
		
		return retValue;
	}

	public CeConnectionUtil getCeConnectionUtil() {
		return ceConnectionUtil;
	}

	public void setCeConnectionUtil(CeConnectionUtil ceConnectionUtil) {
		this.ceConnectionUtil = ceConnectionUtil;
	}

}
